package com.ctsi.ssdc.service.impl;

import com.ctsi.ssdc.entity.SocialRetailSales;
import com.ctsi.ssdc.mapper.SocialRetailSalesMapper;
import com.ctsi.ssdc.service.SocialRetailSalesService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;
import javax.annotation.Resource;

/**
 * 分区镇社零额(SocialRetailSales)表服务实现类
 *
 * @author makejava
 * @since 2023-03-11 22:08:23
 */
@Service("socialRetailSalesService")
public class SocialRetailSalesServiceImpl implements SocialRetailSalesService {
    @Resource
    private SocialRetailSalesMapper socialRetailSalesMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SocialRetailSales queryById(Long id) {
        return this.socialRetailSalesMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param socialRetailSales 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SocialRetailSales> queryByPage(SocialRetailSales socialRetailSales, PageRequest pageRequest) {
        long total = this.socialRetailSalesMapper.count(socialRetailSales);
        return new PageImpl<>(this.socialRetailSalesMapper.queryAllByLimit(socialRetailSales, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param socialRetailSales 实例对象
     * @return 实例对象
     */
    @Override
    public SocialRetailSales insert(SocialRetailSales socialRetailSales) {
        this.socialRetailSalesMapper.insert(socialRetailSales);
        return socialRetailSales;
    }

    /**
     * 修改数据
     *
     * @param socialRetailSales 实例对象
     * @return 实例对象
     */
    @Override
    public SocialRetailSales update(SocialRetailSales socialRetailSales) {
        this.socialRetailSalesMapper.update(socialRetailSales);
        return this.queryById(socialRetailSales.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.socialRetailSalesMapper.deleteById(id) > 0;
    }
    
     /**
     *  批量添加数据
     * @param list
     * @return 是否成功
     */
    @Override
    public boolean insertBatch(List<SocialRetailSales> list) {
        int i = this.socialRetailSalesMapper.insertBatch(list);
        return i>0;
    }

    /**
     * 根据日期删除
     * @param date
     * @return 是否成功
     */
    @Override
    public boolean removeByDate(Date date) {
        return socialRetailSalesMapper.removeByDate(date);
    }
}
